$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'gaokaobaobei/zhaosheng/list',
        datatype: "json",
        colModel: [
			{ label: '姓名', name: 'name', index: 'name', width: 60 },
			{ label: '考号', name: 'candidateNumber', index: 'candidate_number', width: 110},
			{ label: '文理属性', name: 'wlProperty', index: 'wl_property', width: 60 },
			{ label: '分数', name: 'score', index: 'score', width: 60 },
			{ label: '高中', name: 'highSchool', index: 'high_school', width: 100 },
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 },
			{ label: '报备时间', name: 'creationDate', index: 'creation_date', width: 80 },
			{ label: '备注', name: 'candidateNumber', index: 'candidate_number', width: 150,
				formatter: function (data,a,rows) {

					if(rows.type=='等待录取结果'){
						return `备注:`;
					}else if(rows.type=='审核未通过'){
						return `<font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
					}else{
						return `<font color="#228b22">备注:${rows.school}</font> `;
					}
				if(rows.type=='等待录取结果'){
                    return `${data}<br>备注:<input id="xk${data}" />`;
                }else if(rows.type=='审核未通过'){
					return `${data}<br><font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
                }else{
					return `${data}<br><font color="#228b22">备注:${rows.school}</font> `;
					if(rows.type=='等待录取结果'){
						return `备注:<input id="xk${data}" />`;
					}else if(rows.type=='审核未通过'){
						return `<font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
					}else{
						return `<font color="#228b22">备注:${rows.school}</font> `;
					}
				}

			}},
            { label: '操作', name: 'cz', index: 'cz', width: 80,
                formatter: function (data,a,rows) {

                    if(rows.type=='等待录取结果'){
                        return '<button style="" class="btn btn-success btn-xs" onclick="isbaobei(\''+rows.candidateNumber+'\')">提交审核</button>';

                    }else if(rows.type=='等待审核'){
                        return `<font color="#ffd700">审核中</font>`
                    }else if(rows.type=='审核通过'){
                        return `<font color="#228b22">审核通过</font>`
                    }else if(rows.type=='已过期'){
                        return `<font color="red">已过期</font>`
                    }else if(rows.type=='审核未通过'){
						return '<font color="red">审核未通过</font><button style="" class="btn btn-success btn-xs" onclick="isbaobei(\''+rows.candidateNumber+'\')">再次提交</button>';
                    }

                } },
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

function isbaobei(data1){
	var str=prompt("备注","");
	if(str)
	{
		baobei(data1,str)
	}
}


function baobei(data1,beizhu) {
    // var beizhu = $(`#xk`+data1).val();
	// alert(beizhu)
    // if (beizhu =="" || beizhu == null){
    //     alert("请填写备注");
    //     return ;
    // }
    var data = "beizhu="+beizhu+"&number="+data1;
    var url = "gaokaobaobei/zhaosheng/baobei";
    $.ajax({
        type: "POST",
        url: baseURL + url,
        data: data,
        success: function(r){
            if(r.flag){
                alert("报备成功~", function(index){
					vm.reload();
				})

            } else {
                alert("报备失败了~")
            }
        }
    });
}

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		userBackup: {},
        number:"",
        type:null
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.userBackup = {admissionstype:'夏考',type:'',creationDate:''};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.userBackup.id == null ? "gaokaobaobei/zhaosheng/save" : "gaokaobaobei/zhaosheng/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.userBackup),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "gaokaobaobei/zhaosheng/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "gaokaobaobei/zhaosheng/info/"+id, function(r){
                vm.userBackup = r.userBackup;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'type': vm.type},
                page:page
            }).trigger("reloadGrid");
		}
	}
});